<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">
            <h:form prependId="false">
                <p:panel toggleable="true" id="inventoryView" header="Inventory Overview">
                    <h:panelGrid columns="3">
                        <h:outputLabel value="Total Usage= #{rawMaterialEntityController.totalRMUsage}"/>
                        <p:spacer width="60" height="10"/>
                        <h:outputLabel value="Total Capacity= #{rawMaterialEntityController.totalRMCapacity}"/>
                    </h:panelGrid>

                    <h:panelGrid cellpadding="5" width="400" border="3" columns="2">
                        <h:outputText value=""/>
                        <h:outputText value="Total"/>

                        <h:outputText value="Almonds"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalAlmonds}"/>

                        <h:outputText value="Apples"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalApples}"/>

                        <h:outputText value="Apricots"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalApricots}"/>

                        <h:outputText value="Oats"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalOats}"/>

                        <h:outputText value="Wheat Germ"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalWheatGerm}"/>

                        <h:outputText value="Cinnamon"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalCinnamon}"/>

                        <h:outputText value="Nutmeg"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalNutmeg}"/>

                        <h:outputText value="Cloves"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalCloves}"/>

                        <h:outputText value="Honey"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalHoney}"/>

                        <h:outputText value="Vit Mineral Powder"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalVitMineralPowder}"/>

                        <h:outputText value="Carob Chips"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalCarobChips}"/>

                        <h:outputText value="Protein Powder"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalProteinPowder}"/>

                        <h:outputText value="Cocoa Powder"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalCocoaPowder}"/>

                        <h:outputText value="Hazelnuts"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalHazelnuts}"/>

                        <h:outputText value="Cashew Nuts"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalCashewNuts}"/>

                        <h:outputText value="Walnuts"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalWalnuts}"/>

                        <h:outputText value="Macadamias"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalMacadamias}"/>

                        <h:outputText value="Redcurrants"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalRedcurrants}"/>

                        <h:outputText value="Raisins"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalRaisins}"/>

                        <h:outputText value="Dates"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalDates}"/>

                        <h:outputText value="Kiwis"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalKiwis}"/>

                        <h:outputText value="Peaches"/>
                        <h:outputLabel style="table-layout: center" value="#{rawMaterialEntityController.totalPeaches}"/>
                    </h:panelGrid>

                </p:panel>
                <br/>

                <p:dataGrid var="item" value="#{rawMaterialsLocationEntityController.items}" columns="5">  

                    <p:column>  
                        <p:panel header="#{item.areaCode}" style="text-align:center">  

                            <h:outputLabel value="Usage: #{item.usageKg}/#{item.capacityKg}"/>
                            <p:poll interval="1" update="pbAjax" widgetVar="poll" />  

                            <p:progressBar id="pbAjax" widgetVar="pbAjax" ajax="true" value="#{item.usageKg/10}"/>

                            <br />
                            <p:commandButton image="ui-icon ui-icon-search" update="rmLocationDetail" oncomplete="rmLocationDialog.show()" title="View Detail">  

                                <f:setPropertyActionListener value="#{item}"   
                                                             target="#{rawMaterialEntityController.viewLocation}" />  
                            </p:commandButton> 
                            
                             <p:commandButton image="ui-icon ui-icon-alert" update="expiringBatchTable" oncomplete="rmExpirationDialog.show()" title="View Expiring Batches">  

                                <f:setPropertyActionListener value="#{item}"   
                                                             target="#{rawMaterialEntityController.expiringRMInLocation}" /> 
                                
                            </p:commandButton>  

                        </p:panel>  
                    </p:column>  

                </p:dataGrid>  
            </h:form>


            <p:dialog header="Location Detail" widgetVar="rmLocationDialog" width="400" height="800" modal="true">  
                <p:outputPanel id="rmLocationDetail" style="text-align:center;" layout="block">  

                    <h:panelGrid width="360" border="3" columns="2" cellpadding="5">  
                        <h:outputLabel for="Oats" value="Oats " />  
                        <h:outputText id="Oats" value="#{rawMaterialEntityController.oats}" />  

                        <h:outputLabel for="WheatGerm" value="Wheat Germ " />  
                        <h:outputText id="WheatGerm" value="#{rawMaterialEntityController.wheatGerm}" />  

                        <h:outputLabel for="Cinnamon" value="Cinnamon " />  
                        <h:outputText id="Cinnamon" value="#{rawMaterialEntityController.cinnamon}" />  

                        <h:outputLabel for="Nutmeg" value="Nutmeg " />  
                        <h:outputText id="Nutmeg" value="#{rawMaterialEntityController.nutmeg}" />  

                        <h:outputLabel for="Cloves" value="Cloves " />  
                        <h:outputText id="Cloves" value="#{rawMaterialEntityController.cloves}" />  

                        <h:outputLabel for="Honey" value="Honey " />  
                        <h:outputText id="Honey" value="#{rawMaterialEntityController.honey}" />  

                        <h:outputLabel for="CanolaOil" value="Canola Oil " />  
                        <h:outputText id="CanolaOil" value="#{rawMaterialEntityController.canolaOil}" />  

                        <h:outputLabel for="VitMineralPowder" value="Vit Mineral Powder " />  
                        <h:outputText id="VitMineralPowder" value="#{rawMaterialEntityController.vitMineralPowder}" />  

                        <h:outputLabel for="CarobChips" value="Carob Chips " />  
                        <h:outputText id="CarobChips" value="#{rawMaterialEntityController.carobChips}" />  

                        <h:outputLabel for="CocoaPowder" value="Cocoa Powder " />  
                        <h:outputText id="CocoaPowder" value="#{rawMaterialEntityController.cocoaPowder}" />  

                        <h:outputLabel for="Hazelnuts" value="Hazelnuts " />  
                        <h:outputText id="Hazelnuts" value="#{rawMaterialEntityController.hazelnuts}" />  

                        <h:outputLabel for="CashewNuts" value="Cashew Nuts " />  
                        <h:outputText id="CashewNuts" value="#{rawMaterialEntityController.cashewNuts}" />  

                         <h:outputLabel for="Walnuts" value="Walnuts " />  
                        <h:outputText id="Walnuts" value="#{rawMaterialEntityController.walnuts}" /> 
                        
                         <h:outputLabel for="Almonds" value="Almonds " />  
                        <h:outputText id="Almonds" value="#{rawMaterialEntityController.almonds}" /> 
                        
                           <h:outputLabel for="Macadamias" value="Macadamias " />  
                        <h:outputText id="Macadamias" value="#{rawMaterialEntityController.macadamias}" /> 
                        
                            <h:outputLabel for="Redcurrants" value="Redcurrants " />  
                        <h:outputText id="Redcurrants" value="#{rawMaterialEntityController.redcurrants}" /> 
                         
                            <h:outputLabel for="Raisins" value="Raisins " />  
                        <h:outputText id="Raisins" value="#{rawMaterialEntityController.raisins}" /> 
                        
                            <h:outputLabel for="Dates" value="Dates " />  
                        <h:outputText id="Dates" value="#{rawMaterialEntityController.dates}" /> 
                        
                          <h:outputLabel for="Apricots" value="Apricots " />  
                        <h:outputText id="Apricots" value="#{rawMaterialEntityController.apricots}" /> 
                       
                             <h:outputLabel for="Kiwis" value="Kiwis " />  
                        <h:outputText id="Kiwis" value="#{rawMaterialEntityController.kiwis}" /> 
                        
                            <h:outputLabel for="Apples" value="Apples " />  
                        <h:outputText id="Apples" value="#{rawMaterialEntityController.apples}" /> 
                        
                           <h:outputLabel for="Peaches" value="Peaches"/>  
                        <h:outputText id="Peaches" value="#{rawMaterialEntityController.peaches}" /> 

                    </h:panelGrid>  
                </p:outputPanel>  
            </p:dialog>
            
            <p:dialog id="expirationDialog" header="Raw Materials Expiring Within 30 days" widgetVar="rmExpirationDialog" width="600" height="250" modal="true">  
                <h:form prependId="false">
                    <p:dataTable id="expiringBatchTable" var="expiringBatch" value="#{rawMaterialEntityController.expiringBatchesInLocation}" >
                        <p:column headerText="Batch ID">
                            <h:outputLabel for="batchId" value="#{expiringBatch.id}" />
                        </p:column>
                        <p:column headerText="Expiry Date">
                            <h:outputLabel for="batchExpiryDate" value="#{expiringBatch.expiryDate}" />
                        </p:column>
                        <p:column headerText="Product">
                            <h:outputLabel for="batchProductName" value="#{expiringBatch.product.productName}" />

                        </p:column>
                        <p:column headerText="Quantity">
                            <h:outputLabel for="batchQuantity" value="#{expiringBatch.inventory.currentQuantity}" />
                        </p:column>
                         <p:column>
                             <p:commandButton ajax="false" value="Remove">
                                 <f:setPropertyActionListener target="#{rawMaterialEntityController.batchToRemove}"
                                                              value="#{expiringBatch}"/>                                                         
                             </p:commandButton>
                        </p:column>

                    </p:dataTable>
                </h:form>
            </p:dialog> 




        </ui:define>
    </ui:composition>

</html>
